const fs = require('fs');
const path = require('path');

function countFilesSync(dirPath, includeSubdirectories = false) {
  let count = 0;
  const files = fs.readdirSync(dirPath, { withFileTypes: true });

  for (const file of files) {
    if (file.isFile()) {
      count += 1;
    } else if (file.isDirectory() && includeSubdirectories) {
      count += countFilesSync(path.join(dirPath, file.name), true);
    }
  }

  return count;
}

// 使用示例
const directoryPath = 'F:\\code\\companyProject\\LeadArt\\ACCSv5-ui\\src'; // 替换为目标目录路径

try {
  const count = countFilesSync(directoryPath, true);
  console.log(`目录 "${directoryPath}" 中的文件数量为：${count}`);
} catch (err) {
  console.error('读取目录时出错:', err);
}
